<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>时光荏苒 - 一分耕耘，一分收获</title><meta name="author" content="Lancer代良晨"><meta name="copyright" content="Lancer代良晨"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="代良晨的博客">
<meta property="og:type" content="website">
<meta property="og:title" content="时光荏苒">
<meta property="og:url" content="https://lancerdai.gitee.io/index.html">
<meta property="og:site_name" content="时光荏苒">
<meta property="og:description" content="代良晨的博客">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lancerdai.gitee.io/null">
<meta property="article:author" content="Lancer代良晨">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lancerdai.gitee.io/null"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lancerdai.gitee.io/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  hexoversion: '5.1.1',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isSidebar: false,
  postUpdate: '2020-10-16 22:45:12'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {
  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }

  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }
})()</script><meta name="generator" content="Hexo 5.1.1"></head><body><div id="mobile-sidebar"><div id="menu_mask"></div><div id="mobile-sidebar-menus"><div class="mobile_author_icon"><img class="avatar-img" src="/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="mobile_post_data"><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/archives/"><div class="headline">文章</div><div class="length_num">13</div></a></div></div><div class="mobile_data_item is-center">      <div class="mobile_data_link"><a href="/tags/"><div class="headline">标签</div><div class="length_num">16</div></a></div></div><div class="mobile_data_item is-center">     <div class="mobile_data_link"><a href="/categories/"><div class="headline">分类</div><div class="length_num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw fas-game"></i><span> game</span></a></li><li><a class="site-page" href="/books/"><i class="fa-fw fas-books"></i><span> books</span></a></li><li><a class="site-page" href="/Gallery/"><i class="fa-fw fas-Gallery"></i><span> Gallery</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div id="body-wrap"><header class="full_page" id="page-header" style="background-image: url(http://p5.qhimg.com/bdr/__100/t012923b389a2f96e3e.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">时光荏苒</a></span><span id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw fas-game"></i><span> game</span></a></li><li><a class="site-page" href="/books/"><i class="fa-fw fas-books"></i><span> books</span></a></li><li><a class="site-page" href="/Gallery/"><i class="fa-fw fas-Gallery"></i><span> Gallery</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="site-info"><h1 id="site-title">时光荏苒</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout_page" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left_radius"><a href="/2020/10/16/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E5%AD%90%E7%B3%BB%E7%BB%9F/" title="类加载子系统">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="类加载子系统"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/10/16/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E5%AD%90%E7%B3%BB%E7%BB%9F/" title="类加载子系统">类加载子系统</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-10-16T14:39:46.000Z" title="发表于 2020-10-16 22:39:46">2020-10-16</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/java%E8%99%9A%E6%8B%9F%E6%9C%BA/">java虚拟机</a></span></div><div class="content">整体流程图
   

 


ClassLoader作用
类加载子系统负责从文件或者网络中加载class文件，class文件在文件开头有特定的文件标识。
ClassLoader只负责class文件的加载，至于它是否可以运行，则又Excution Engine决定
加载的类信息存放于称为方法区的内存空间，除了类的信息外，方法区还会存放运行时常量池信息，可能还包括字符串字面量和数字常量（这部分常量信息是class文件中常量池部分的内存映射）

ClassLoader的角色
   

 


class file存在于本地磁盘上，可以理解为设计师画在纸上的模版，而最终这个模版在执行的时候，需要加载到jvm当中来，根据这个文件实例化出n个一模一样的实例
class file加载到jvm中，被称为DNA元数据模板，存在方法区
在class文件-&gt;JVM-&gt;元数据模板，这个过程中需要一个运输工具扮演快递员的角色，就是我们的类加载器Class Loader。

类的加载过程
   

 

第一步：加载 Loading
通过一个类的全限定名获取此类的二进制字节流
将这个字节流所代表的静态 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/2020/10/12/jvm%E8%BF%90%E8%A1%8C%E6%97%B6%E6%95%B0%E6%8D%AE%E5%8C%BA/" title="jvm运行时数据区">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="jvm运行时数据区"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/10/12/jvm%E8%BF%90%E8%A1%8C%E6%97%B6%E6%95%B0%E6%8D%AE%E5%8C%BA/" title="jvm运行时数据区">jvm运行时数据区</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-10-12T11:44:24.000Z" title="发表于 2020-10-12 19:44:24">2020-10-12</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/java%E8%99%9A%E6%8B%9F%E6%9C%BA/">java虚拟机</a></span></div><div class="content">架构图
   

 



线程共享数据区堆用于存放对象实例堆本身没有分区，所有的分区方法都只是逻辑分区，仅用于帮助理解，如：GC分为新生代、老年代、永久代、Eden等，线程可以有线程缓冲区堆内存在物理上可以是不连续的，逻辑上连续即可。
方法区用于存储被虚拟机加载的类型信息、常量、静态变量、即时编译后的代码缓存等数据。

方法区容易和“永久代”混淆老版本中，为了方便，用堆的永久代方法实现方法区java8中，完全舍弃永久代，用元空间实现方法区

永久代的约束宽松不需要连续内存空间可以固定大小，也可以可扩展可以不实现垃圾回收（可能会导致内存溢出）
运行时常量用于存储编译时期生成的各种字面量与符号引用具有动态性：不一定只有编译器生成，运行期间可新增，如：string的intern()方法
线程私有内存程序计数器线程所执行的字节码的行号指示器
java虚拟机栈描述Java方法执行的内存模型方法被执行时，创建一个栈帧，用于存储局部变量表、操作数栈、动态连接、方法出口灯信息。局部变量表存基本数据类型，对象只保存指针局部变量表数量在编译时确定，运行时数量一旦分配不会改变方法执行完毕，出栈
本地方法栈 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/2020/09/25/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%A4%A7%E8%B1%A1-Thinking-in-UML%E3%80%8B/" title="读书笔记--《大象:Thinking in UML》">     <img class="post_bg" src="http://browser9.qhimg.com/bdr/__100/t012468d019e3ce466b.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="读书笔记--《大象:Thinking in UML》"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/09/25/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%A4%A7%E8%B1%A1-Thinking-in-UML%E3%80%8B/" title="读书笔记--《大象:Thinking in UML》">读书笔记--《大象:Thinking in UML》</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-09-25T03:04:22.000Z" title="发表于 2020-09-25 11:04:22">2020-09-25</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E6%8A%80%E6%9C%AF/">读书笔记-技术</a></span></div><div class="content">
中国象棋，只有32棵棋子，规则简单，但水平高低之间，不在于是否掌握了马走日象走田。正如UML，简单说只有元素、视图与模型，但水平高低之间，绝不在于谁能在视图之上画出各种元素堆积的模型，而是在于谁能够借助UML提供的这些工具，灵活自如地为复杂项目的开发提供一个成熟的、统一的、系统的、广泛适用的系统分析设计与建模方法，即软件的统一过程。


老子说，大象希形，大音希声。我的理解大概是，象至极大，形之其次；音至极美，声之其次；器至极巧，工之其次。能把UML讲得如蛋清般清沏，已属罕见，在读完这本书之后，又突然发现已然把朝夕膜拜的RUP之精髓收于囊中，同时让开发框架、软件架构、设计模式、分析、设计与建模等庞大而复杂的概念，再也不像如鲠在喉，真的难以形容这是一种多么美妙的感觉。之余，不得不叹服作者功力之厚、思想之深、语言之美、构思之巧，一切莫不象至极大，故此书第一版，命名为《大象》。


古人将知识分为“技”和“道”，习技固然可以成为人杰，而悟道才能羽化升仙。


人类自从有思想以来，就在不断探寻和认识自己所生活的这个世界。从本质上说，面向过程和面向对象都是人们认识这个世界的方法；而具体的技术， ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/2020/09/24/SpringMVC-WebSocket-%E5%AE%9E%E7%8E%B0%E7%BE%A4%E8%81%8A/" title="SpringMVC + WebSocket 实现群聊">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringMVC + WebSocket 实现群聊"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/09/24/SpringMVC-WebSocket-%E5%AE%9E%E7%8E%B0%E7%BE%A4%E8%81%8A/" title="SpringMVC + WebSocket 实现群聊">SpringMVC + WebSocket 实现群聊</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-09-24T11:28:13.000Z" title="发表于 2020-09-24 19:28:13">2020-09-24</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/JavaWeb/">JavaWeb</a></span></div><div class="content">
用SpringMVC+WebScoket技术，实现群聊功能

1 新建项目1、 新建一个空的Maven项目
2、 在pom.xml文件中加入以下依赖：
123456789101112131415161718192021222324252627282930313233343536&lt;properties&gt;    &lt;spring.version&gt;5.1.5.RELEASE&lt;/spring.version&gt;&lt;/properties&gt;&lt;dependencies&gt;    &lt;!--SpringMVC依赖包--&gt;    &lt;dependency&gt;        &lt;groupId&gt;org.springframework&lt;/groupId&gt;        &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;        &lt;version&gt;$&#123;spring.version&#125;&lt;/version&gt;    &lt; ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/2020/06/17/Volatile%E5%8F%AF%E8%A7%81%E6%80%A7%E4%BB%A3%E7%A0%81%E9%AA%8C%E8%AF%81/" title="Volatile可见性代码验证">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Volatile可见性代码验证"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/06/17/Volatile%E5%8F%AF%E8%A7%81%E6%80%A7%E4%BB%A3%E7%A0%81%E9%AA%8C%E8%AF%81/" title="Volatile可见性代码验证">Volatile可见性代码验证</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-06-17T08:07:22.000Z" title="发表于 2020-06-17 16:07:22">2020-06-17</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/">多线程</a></span></div><div class="content">
Volatile可见性是指：在JMM模型中，所有的线程操作数据时，都不能直接操作主内存里的数据，都需要将数据复制一份到线程内存中，只能修改线程内存中的数据（详细可以查找JMM相关知识）。然而，在一个线程中修改了某一个变量的值之后，应该立即将线程内存中修改的值，同步到主内存中，并通知其他线程，让其他线程重新获取变量值。

1、正确的样例代码1、 首先定义一个数据类这里有两个变量，一个用volatile修饰，另一个没有；
12345678910public class MyData &#123;    int number1 = 0;    volatile int number2 = 0;    public void add()&#123;        this.number1 = 11;        this.number2 = 22;    &#125;&#125;

2、 新建一个测试类，内容如下，
12345678910111213141516171819202122232425262728import java.util.concurrent.TimeUnit;publ ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/2020/02/19/Java%E6%93%8D%E4%BD%9CHDFS%E7%A4%BA%E4%BE%8B/" title="Java操作HDFS示例">     <img class="post_bg" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java操作HDFS示例"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/02/19/Java%E6%93%8D%E4%BD%9CHDFS%E7%A4%BA%E4%BE%8B/" title="Java操作HDFS示例">Java操作HDFS示例</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-02-19T11:40:59.000Z" title="发表于 2020-02-19 19:40:59">2020-02-19</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="content">1. 环境准备
大数据集群一套，没有的可以自己本地搭建一套（参考地址：https://www.jianshu.com/p/2c2ae6490fa0）
本地安装JDK
本地安装IDEA或者Eclipse

2. 创建Maven项目在IDEA工具中创建一个maven项目，并在pom.xml中添加以下依赖：
12345678910111213141516171819202122232425262728293031323334&lt;dependencies&gt;		&lt;dependency&gt;			&lt;groupId&gt;junit&lt;/groupId&gt;			&lt;artifactId&gt;junit&lt;/artifactId&gt;			&lt;version&gt;RELEASE&lt;/version&gt;		&lt;/dependency&gt;		&lt;dependency&gt;			&lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;			&lt;artifactId&gt;log4 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/2020/02/17/Hadoop%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%B8%8E%E4%B8%89%E7%A7%8D%E8%BF%90%E8%A1%8C%E6%A8%A1%E5%BC%8F/" title="Hadoop的配置文件与三种运行模式">     <img class="post_bg" src="http://p1.qhimg.com/bdr/__100/t018eb997ba237f590f.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hadoop的配置文件与三种运行模式"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/02/17/Hadoop%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%B8%8E%E4%B8%89%E7%A7%8D%E8%BF%90%E8%A1%8C%E6%A8%A1%E5%BC%8F/" title="Hadoop的配置文件与三种运行模式">Hadoop的配置文件与三种运行模式</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-02-17T11:04:26.000Z" title="发表于 2020-02-17 19:04:26">2020-02-17</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="content">1. 配置文件简介首先，在hadoop官网中可以看到，hadoop有四个核心模块，如下图：


   



 



Hadoop Common     (公共的工具，为其他模块提供支撑)
Hadoop Distributed File System (HDFS)  (是一个分布式文件系统，提供高吞吐量数据存储)
Hadoop YARN                    (是一框架，负责任务调度和集群资源管理)
Hadoop MapReduce    (负责大数据集合的并行计算)


然而，我们安装完Hadoop的安装包后，在etc/hadoop目录中，可以看到全部的配置文件如下
123456789101112131415161718192021222324252627282930313233343536[root@hadoop101 hadoop]# pwd&#x2F;opt&#x2F;module&#x2F;hadoop-2.7.2&#x2F;etc&#x2F;hadoop[root@hadoop101 hadoop]# lltotal 156-rw-r--r--. 1 10 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/2020/02/16/Hadoop%E4%BC%AA%E5%88%86%E5%B8%83%E5%BC%8F%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E4%B8%8E%E5%90%AF%E5%8A%A8/" title="Hadoop伪分布式环境配置与启动">     <img class="post_bg" src="http://p3.qhimg.com/bdr/__100/t012468d019e3ce466b.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hadoop伪分布式环境配置与启动"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/02/16/Hadoop%E4%BC%AA%E5%88%86%E5%B8%83%E5%BC%8F%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E4%B8%8E%E5%90%AF%E5%8A%A8/" title="Hadoop伪分布式环境配置与启动">Hadoop伪分布式环境配置与启动</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-02-16T11:54:24.000Z" title="发表于 2020-02-16 19:54:24">2020-02-16</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="content">1. 环境准备在一台linux机器上，安装好hadoop运行环境，安装方式请查看：HADOOP运行环境搭建
2. 启动HDFS并运行MapReduce程序2.1. 配置集群1. 配置：hadoop-env.shLinux系统中获取JDK的安装路径：
12[root@ hadoop101 ~]# echo $JAVA_HOME/opt/module/jdk1.8.0_144
编辑hadoop-env.sh，修改hadoop-env.sh中的JAVA_HOME 路径：
1export JAVA_HOME=/opt/module/jdk1.8.0_144
2. 配置：core-site.xml首先文件的存取目录不能停留在本地，要用HDFS上的文件，就需要配置HDFS的NameNode的地址。所以需要在core-site.xml中增加以下配置
12345678910&lt;!-- 指定HDFS中NameNode的地址 --&gt;&lt;property&gt;&lt;name&gt;fs.defaultFS&lt;/name&gt; &lt;value&gt;hdfs://hadoop101 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/2020/02/16/Hadoop%E7%9A%84%E5%8D%95%E6%9C%BA%E6%A8%A1%E5%BC%8F%E5%92%8C%E5%AE%98%E6%96%B9%E7%A4%BA%E4%BE%8B/" title="Hadoop的单机模式和官方示例">     <img class="post_bg" src="http://p5.qhimg.com/bdr/__100/t016591fff7fda9d11f.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hadoop的单机模式和官方示例"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/02/16/Hadoop%E7%9A%84%E5%8D%95%E6%9C%BA%E6%A8%A1%E5%BC%8F%E5%92%8C%E5%AE%98%E6%96%B9%E7%A4%BA%E4%BE%8B/" title="Hadoop的单机模式和官方示例">Hadoop的单机模式和官方示例</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-02-16T03:58:31.000Z" title="发表于 2020-02-16 11:58:31">2020-02-16</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="content">一、 单机模式说明
单机模式是Hadoop的默认模式。又称本地模式、独立模式等。因为不需要与其他节点交互，单机模式就不使用HDFS，也不加载任何Hadoop的守护进程。该模式主要用于开发调试MapReduce程序的应用逻辑。

1. 环境准备在一台linux机器上，安装好hadoop运行环境，安装方式请查看：HADOOP运行环境搭建
2. 配置说明首先说明，**单机模式在安装之后不需要修改任何配置，配置文件为空即可！**之所以单机模式不需要任何配置文件，是因为配置文件不配置时，系统默认值即为单机模式所需



配置文件名
配置项
配置项含义
默认值
默认值含义



core-site.xml
fs.defaultFS
默认文件系统的名称，可以是HDFS的NameNode地址或者本地
file:///
文件读取和存储都在本地


mapred-site.xml
mapreduce.framework.name
指定执行MapReduce任务的框架。可以是本地、经典、yarn
local
指定MR运行在本地


二、本地运行官方示例搭建完成Hadoop运行环境之后，无需任何配置，即可开始 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/2020/02/15/Hadoop%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E6%95%99%E7%A8%8B/" title="Hadoop运行环境搭建教程">     <img class="post_bg" src="http://p1.qhimg.com/bdm/1600_900_85/t013777ac0e30cc6227.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hadoop运行环境搭建教程"></a></div><div class="recent-post-info"><a class="article-title" href="/2020/02/15/Hadoop%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E6%95%99%E7%A8%8B/" title="Hadoop运行环境搭建教程">Hadoop运行环境搭建教程</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2020-02-15T11:04:26.000Z" title="发表于 2020-02-15 19:04:26">2020-02-15</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox article-meta__icon"></i><a class="article-meta__categories" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="content">1. 环境准备：一台linux机器，可以是本地VMware安装的虚拟机，或者一台真实的linux机器都可以。

如果是本地安装的虚拟机，需要预先配置好以下几点：

配置机器静态IP（防止重启时IP变动）
修改主机名（方便配置）
关闭防火墙（防止端口被禁用）


2. 安装包准备
jdk安装包下载地址：https://www.oracle.com/java/technologies/javase-jdk8-downloads.html推荐版本：jdk8及以上
hadopp安装包下载地址：http://archive.apache.org/dist/hadoop/core/推荐版本：2.7.23. 执行安装1. 上传文件
在linux上新建目录/opt/software，/opt/module
上传jdk安装包和hadoop安装包2. 安装jdk
解压jdk包到/opt/module目录  1[root@hadoop101 software]# tar -zxvf jdk-8u144-linux-x64.tar.gz -C /opt/module/
配置jdk环境变量先获取jdk解压路径， ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="extend next" rel="next" href="/page/2/"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="/null" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Lancer代良晨</div><div class="author-info__description">代良晨的博客</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length_num">13</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length_num">16</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length_num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div></div><div class="sticky_layout"><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2020/10/16/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E5%AD%90%E7%B3%BB%E7%BB%9F/" title="类加载子系统"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="类加载子系统"/></a><div class="content"><a class="title" href="/2020/10/16/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E5%AD%90%E7%B3%BB%E7%BB%9F/" title="类加载子系统">类加载子系统</a><time datetime="2020-10-16T14:39:46.000Z" title="发表于 2020-10-16 22:39:46">2020-10-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/10/12/jvm%E8%BF%90%E8%A1%8C%E6%97%B6%E6%95%B0%E6%8D%AE%E5%8C%BA/" title="jvm运行时数据区"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="jvm运行时数据区"/></a><div class="content"><a class="title" href="/2020/10/12/jvm%E8%BF%90%E8%A1%8C%E6%97%B6%E6%95%B0%E6%8D%AE%E5%8C%BA/" title="jvm运行时数据区">jvm运行时数据区</a><time datetime="2020-10-12T11:44:24.000Z" title="发表于 2020-10-12 19:44:24">2020-10-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/09/25/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%A4%A7%E8%B1%A1-Thinking-in-UML%E3%80%8B/" title="读书笔记--《大象:Thinking in UML》"><img src="http://browser9.qhimg.com/bdr/__100/t012468d019e3ce466b.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="读书笔记--《大象:Thinking in UML》"/></a><div class="content"><a class="title" href="/2020/09/25/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E3%80%8A%E5%A4%A7%E8%B1%A1-Thinking-in-UML%E3%80%8B/" title="读书笔记--《大象:Thinking in UML》">读书笔记--《大象:Thinking in UML》</a><time datetime="2020-09-25T03:04:22.000Z" title="发表于 2020-09-25 11:04:22">2020-09-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/09/24/SpringMVC-WebSocket-%E5%AE%9E%E7%8E%B0%E7%BE%A4%E8%81%8A/" title="SpringMVC + WebSocket 实现群聊"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringMVC + WebSocket 实现群聊"/></a><div class="content"><a class="title" href="/2020/09/24/SpringMVC-WebSocket-%E5%AE%9E%E7%8E%B0%E7%BE%A4%E8%81%8A/" title="SpringMVC + WebSocket 实现群聊">SpringMVC + WebSocket 实现群聊</a><time datetime="2020-09-24T11:28:13.000Z" title="发表于 2020-09-24 19:28:13">2020-09-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/06/17/Volatile%E5%8F%AF%E8%A7%81%E6%80%A7%E4%BB%A3%E7%A0%81%E9%AA%8C%E8%AF%81/" title="Volatile可见性代码验证"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Volatile可见性代码验证"/></a><div class="content"><a class="title" href="/2020/06/17/Volatile%E5%8F%AF%E8%A7%81%E6%80%A7%E4%BB%A3%E7%A0%81%E9%AA%8C%E8%AF%81/" title="Volatile可见性代码验证">Volatile可见性代码验证</a><time datetime="2020-06-17T08:07:22.000Z" title="发表于 2020-06-17 16:07:22">2020-06-17</time></div></div></div></div></div><div class="card-widget card-categories"><div class="card-content"><div class="item-headline"><i class="fas fa-folder-open"></i><span>分类</span></div><ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/JavaWeb/"><span class="card-category-list-name">JavaWeb</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Linux/"><span class="card-category-list-name">Linux</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/hexo%E6%B5%8B%E8%AF%95/"><span class="card-category-list-name">hexo测试</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/java%E8%99%9A%E6%8B%9F%E6%9C%BA/"><span class="card-category-list-name">java虚拟机</span><span class="card-category-list-count">2</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/"><span class="card-category-list-name">多线程</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/"><span class="card-category-list-name">大数据</span><span class="card-category-list-count">5</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E7%AE%97%E6%B3%95/"><span class="card-category-list-name">算法</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0-%E6%8A%80%E6%9C%AF/"><span class="card-category-list-name">读书笔记-技术</span><span class="card-category-list-count">1</span></a></li>
            
            </ul></div></div><div class="card-widget card-tags"><div class="card-content"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/Hadoop/" style="font-size: 1.4em; color: #99a5b6">Hadoop</a> <a href="/tags/Linux/" style="font-size: 1.3em; color: #99a1ac">Linux</a> <a href="/tags/Shell/" style="font-size: 1.1em; color: #999">Shell</a> <a href="/tags/SpringMVC/" style="font-size: 1.1em; color: #999">SpringMVC</a> <a href="/tags/UML/" style="font-size: 1.1em; color: #999">UML</a> <a href="/tags/WebSocket/" style="font-size: 1.1em; color: #999">WebSocket</a> <a href="/tags/java/" style="font-size: 1.5em; color: #99a9bf">java</a> <a href="/tags/javascript/" style="font-size: 1.1em; color: #999">javascript</a> <a href="/tags/jvm/" style="font-size: 1.2em; color: #999da3">jvm</a> <a href="/tags/maven/" style="font-size: 1.1em; color: #999">maven</a> <a href="/tags/shell/" style="font-size: 1.1em; color: #999">shell</a> <a href="/tags/test/" style="font-size: 1.1em; color: #999">test</a> <a href="/tags/%E5%86%85%E5%AD%98/" style="font-size: 1.1em; color: #999">内存</a> <a href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 1.1em; color: #999">多线程</a> <a href="/tags/%E7%AE%97%E6%B3%95/" style="font-size: 1.1em; color: #999">算法</a> <a href="/tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" style="font-size: 1.1em; color: #999">面向对象</a></div></div></div><div class="card-widget card-archives"><div class="card-content"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2020/10/"><span class="card-archive-list-date">十月 2020</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2020/09/"><span class="card-archive-list-date">九月 2020</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2020/06/"><span class="card-archive-list-date">六月 2020</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2020/02/"><span class="card-archive-list-date">二月 2020</span><span class="card-archive-list-count">6</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2019/05/"><span class="card-archive-list-date">五月 2019</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2017/12/"><span class="card-archive-list-date">十二月 2017</span><span class="card-archive-list-count">1</span></a></li></ul></div></div><div class="card-widget card-webinfo"><div class="card-content"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">13</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2020-10-16T14:45:11.867Z"></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 By Lancer代良晨</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><section id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></section><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></div></body></html>